using System;
using System.Windows.Forms;
using System.Drawing;
using System.Resources;

namespace WinformToolkit.Drawing
{
    /// <summary>
    /// Rectangle tool
    /// </summary>
    class ToolRectangle : WinformToolkit.Drawing.ToolObject
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger("ToolRectangle");

        public ToolRectangle()
        {
            Cursor = this.LoadCursor("Rectangle.cur");
        }

        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            base.OnMouseDown(drawArea, e);

            PropertiesRectangle properties = new PropertiesRectangle(e.X, e.Y, 1, 1);

            DrawRectangle drawRectangle = new DrawRectangle(properties)
            {
                ID = drawArea.GenerateObjectId(),
                Color = drawArea.PenColor,
                PenWidth = drawArea.PenWidth,
            };
            drawRectangle.UpdateOriginal(drawArea.CanvasRectangle, drawArea.Scale);

            AddNewObject(drawArea, drawRectangle);
        }

        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            base.OnMouseMove(drawArea, e);

            drawArea.Cursor = Cursor;

            if (e.Button == MouseButtons.Left)
            {
                Point point = new Point(e.X, e.Y);
                drawArea.GraphicsList[0].MoveHandleTo(point, 5);
                drawArea.GraphicsList[0].UpdateOriginal(drawArea.CanvasRectangle, drawArea.Scale);
                drawArea.Invalidate();
            }
        }

        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            base.OnMouseUp(drawArea, e);
        }
    }
}
